package com.wudl.juc;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * @author ：wudl
 * @date ：Created in 2021-11-28 23:15
 * @description：
 * @modified By：
 * @version: 1.0
 */

public class MyCallable implements Callable<String> {
    @Override
    public String call() throws Exception {
        System.out.println("调用call----->");
        Thread.sleep(5000);
        return  "调用call----->";
    }

    public static void main(String[] args) throws ExecutionException, InterruptedException {

        MyCallable myCallable = new MyCallable();
        FutureTask<String> stringFutureTask = new FutureTask<>(myCallable);

        // 启动线程  执行callable 的业务
        new Thread(stringFutureTask).start();

        // 同步等待callable 的返回值
        String result = stringFutureTask.get();
        System.out.println("result----->"+result);
        System.out.println("main---线程运行结束------>");

    }
}
